home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-31 | 3.8 KB | 174 lines | [TEXT/CWIE] |
- // Sprocket Framework header file
- // Menubar.h
-
-
- #ifndef _MENUBAR_
- #define _MENUBAR_
-
- #include <Menus.h>
- #include "SortedDynamicArray.h"
-
- // bare types are dangerous, eh?
-
- typedef SInt16 MenuID;
- typedef UInt16 MenuItemID;
- typedef SInt16 MenuBarTemplateID;
- typedef UInt32 CommandID;
-
- // Some types which should probably be defined in <Menus.h>
- // NOTE: These must be aligned on 2-byte boundaries
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- // Kinda strange that NONE of the toolbox headers define
- // the ON-DISK representations of their template resources, eh?
-
- typedef struct MenuBarResource MenuBarResource;
-
- struct MenuBarResource
- {
- UInt16 numberOfMenus;
- SInt16 menuIDList[1];
- };
-
-
- // CMNU Resources look just like 'MENU' resources, except that
- // each item is appended with an extra (2-byte aligned) longword.
- //
- // They are evil because menu items always start out screwed up
- // because some bright individual decided to START the record
- // with the variable-sized field!.
- //
- // In the long run this is still OK, because ResEdit and Resourceror
- // already create and edit CMNU resources. All the evil is confined
- // within parts of Sprocket you don’t have to modify.
-
- typedef struct CMNUResource CMNUResource;
- typedef struct CMNUItemData CMNUItemData;
-
-
- // CW6 didn’t like having this below the CMNUResource definition,
- // even though CW5 didn’t complain:
-
- struct CMNUItemData
- {
- Str255 itemString; // don’t you hate structures that start out misalinged!
- Byte itemIcon;
- Byte itemCmd;
- Byte itemMark;
- Style itemStyle;
- CommandID itemCommand;
- };
-
-
- struct CMNUResource
- {
- short menuID;
- short menuWidth;
- short menuHeight;
- Handle menuProc;
- long enableFlags;
- Str255 menuTitle;
- CMNUItemData menuData[1]; // here begins evil!
- };
-
-
- // Restore default alignment
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
-
- enum
- {
- kNoMenuID = 0,
- kNoMenuItemID = 0,
- kNoMenuCommandID = 0
- };
-
-
- struct MenuMapping
- {
- MenuID fMenu;
- MenuItemID fItem;
- CommandID fCommand; // the command ID, which must be unique
- };
-
-
- class TMenuItemTable : public TSortedDynamicArray
- {
- virtual CompareResult Compare(ArrayElementPtr element1,
- ArrayElementPtr element2);
- };
-
-
- class TMenuCommandTable : public TSortedDynamicArray
- {
- virtual CompareResult Compare(ArrayElementPtr element1,
- ArrayElementPtr element2);
- };
-
-
- class TMenuBar
- {
- public:
- // Resource ('MBAR' and 'CMNU') Utilities
-
- OSErr GetNewMenuBar(short whichMBAR);
- MenuRef GetMenuFromCMNU(short whichMenu);
-
- // Menu command mapping functions
-
- CommandID GetCommand(MenuID menu, MenuItemID item);
- void GetMenuAndItem(CommandID commandNum, MenuID * returnedMenu, MenuItemID * returnedItem);
-
- OSErr RegisterCommand(CommandID commandNum, MenuID menu, MenuItemID item);
- OSErr UnregisterCommand(CommandID commandNum);
-
- // Menu enable/disable routines for menu items
-
- void EnableCommand(CommandID commandNum, Boolean enable);
- void EnableAndCheckCommand(CommandID commandNum, Boolean enable, Boolean check);
-
- void GetItemString(CommandID commandNum, StringPtr itemString);
- void SetItemString(CommandID commandNum, StringPtr itemString);
-
- void SetItemStyle(CommandID commandNum, Style aStyle);
-
- OSErr HiliteMenusForModalDialog(Boolean hiliting);
-
-
- // helpful utility functions
-
- void HideMenuBar();
- void ShowMenuBar();
-
- void RedrawIfNeeded();
- void Invalidate();
- void Validate();
-
- private:
- // "globals"
-
- static Boolean fgMenuBarNeedsRedraw;
- static Boolean fgMenuBarHidden;
- static short fgMenuBarHeight;
- static RgnHandle fgMenuBarRgn;
-
- // private vars
-
- short fCurrentMBAR;
-
- // mapping tables
-
- TMenuCommandTable fCommandTable;
- TMenuItemTable fMenuItemTable;
-
- // internal methods
-
- MenuRef GetMenuRefAndItemFromCommand(CommandID commandNum, MenuID *menu,MenuItemID *item);
- };
-
- #endif
-